import 'package:flutter/material.dart';
import '../demo/ui_demo.dart';

class MyDemo extends StatelessWidget implements Demo {
  MyDemo(this.title);
  @override
  String title;
  @override
  Widget build(BuildContext context) {
    return  new HomePage(title: this.title,);
  }
}

class HomePage extends StatelessWidget {
  String title;
  HomePage({this.title});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          title: Text(this.title),
          centerTitle: true,
          elevation: 0,
          actions: <Widget>[
            IconSource("LayoutDemo","05"),
          ],
        ),
        body: ListView(
          padding: EdgeInsets.only(left: 10.0,right: 10.0),
          children: <Widget>[
            RowColumnDemo(),
            SizedBoxDemo(),
            AspectRatioDemo(),
            ConstraineDemo(),
          ],
        ),
      ),
    );
  }
}

class IconBadge extends StatelessWidget {
  final IconData icon;
  final double size;
  IconBadge(this.icon, this.size);
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: size + 60,
      height: size + 60,
      decoration: BoxDecoration(
          color: Colors.blueAccent,
          borderRadius: BorderRadius.only(topLeft: Radius.circular(9.0))),
      child: Icon(
        icon,
        size: size,
      ),
    );
  }
}

class RowColumnDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      padding: EdgeInsets.all(5.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        //crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          IconBadge(Icons.pool, 20.0),
          IconBadge(Icons.delete_sweep, 40.0),
          IconBadge(Icons.pages, 20.0),
        ],
      ),
    );
  }
}

class SizedBoxDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      padding: EdgeInsets.all(5.0),
      height: 100.0,
      child: Stack(
        children: <Widget>[
          Container(
            alignment: Alignment(-1.0, 0.0),
            child: Icon(
              Icons.person,
              size: 40,
              color: Colors.white,
            ),
            decoration: BoxDecoration(
                color: Colors.blueAccent, borderRadius: BorderRadius.circular(8.0)),
          ),
          Container(
            child: Icon(Icons.pool,color: Colors.white,size: 35,),
            margin: EdgeInsets.only(left: 50.0,top: 35.0),
          ),
          Positioned(
            child: Icon(Icons.ac_unit,color: Colors.white,),
            top: 10.0,
            right: 10.0,
          ),
          Positioned(
            child: Icon(Icons.ac_unit,size:16.0,color: Colors.white,),
            top: 25.0,
            right: 45.0,
          )
        ],
      )
    );
  }
}
class AspectRatioDemo extends StatelessWidget{
  /**
   * 固定比例的box
   */
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      child: AspectRatio(
          aspectRatio: 4.0/2.0,//宽高比
          child: Container(
            width: 10.0,
            color: Colors.blueAccent,
            child: Icon(Icons.history,size: 45.0,),
          ),
      ),
    );
  }
}
class ConstraineDemo extends StatelessWidget{
  /**
   * 带限制的box
   */
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ConstrainedBox(
      constraints: BoxConstraints(
        minHeight: 100.0,
        maxWidth: 200.0
      ),
      child: Container(
        margin: EdgeInsets.only(top: 10.0),
          child: Container(
            width: 10.0,
            color: Colors.blueAccent,
            child: Icon(Icons.poll,size: 45.0,color: Colors.white,),
          ),
      ),
    );
  }
}
